<template>
  <div class="login">
    <img
      class="log"
      src="img/2.jpg"
      alt=""
    >
    <div class="wen-zi">
      中国移动提供认证服务
    </div>
    <div
      class="deng-lu"
      @click="showPopup"
    >
      一键登录</div>
    <van-popup v-model="show">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="手机号"
          label="手机号"
          placeholder="手机号"
          :rules="[{ required: true, message: '请填写手机号' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px;">
          <van-button
            round
            block
            type="info"
            native-type="submit"
          >提交</van-button>
        </div>
      </van-form>
    </van-popup>
    <div
      class="ti-yan"
      @click="tiYan"
    >
      立即体验
    </div>
    <div class="bt-log">
      <img
        src="img/qq.jpg"
        alt=""
      >
      <img
        src="img/wx.jpg"
        alt=""
      >
      <img
        src="img/wb.jpg"
        alt=""
      >
      <img
        src="img/wy.jpg"
        alt=""
      >
    </div>
    <p class="xie-yi">
      登录即已同意<span>《用户协议》《隐私政策》《儿童隐私政策》</span>
    </p>
    <p class="xie-yi2">
      《中国移动认证服务协议》
    </p>

  </div>

</template>
<script>
import { Toast } from 'vant'
import { getLogin, getuserinfo } from '@/api/login'
export default {
  data: () => ({
    show: false,
    username: '',
    password: '',
    listdata: {}
  }),
  created() {
    // this.getLogin()
    // this.getuserinfo()
  },
  methods: {
    tiYan() {
      this.$router.push('/recommend')
    },
    showPopup() {
      this.show = true
    },
    onSubmit() {
      this.getLogin()
    },
    // 登录
    async getLogin() {
      const res = await getLogin({ phone: this.username, password: this.password })
      if (res.data.code === 200) {
        Toast.success('登录成功')
        this.getuserinfo(res.data.account.id)
      } else if (res.data.code !== 200) {
        Toast.success('手机号或密码错误')
        return false
      }
    },
    // 获取用户信息
    async getuserinfo(id) {
      const res = await getuserinfo(id)
      this.listdata = res.data
      localStorage.listdata = JSON.stringify(res.data)
      this.$router.push('/recommend')
    }
  }
}
</script>
<style lang="less" >
.login {
  width: 100%;
  height: ceil(100vh);
  background-color: #dc2c1f;
  box-sizing: border-box;
  padding-top: 120px;
  .log {
    width: 60px;
    height: 60px;
    display: block;
    margin: 0 auto;
  }
  .wen-zi {
    width: 120px;
    font-size: 2px;
    color: #ccc;
    // margin-top: 240px;
    // margin-left: 100px;
    margin: 0 auto;
    margin-top: 240px;
  }
  .deng-lu {
    width: 252px;
    height: 37px;
    background-color: #fff;
    border-radius: 16px;
    color: red;
    font-size: 14px;
    margin: 0px auto;
    // font-weight: 900;
    line-height: 35px;
    text-align: center;
    margin-top: 15px;
  }
  .ti-yan {
    width: 250px;
    height: 35px;
    background-color: #dc2c1f;
    border-radius: 16px;
    border: 1px solid #ccc;
    color: #fff;
    font-size: 14px;
    margin: 0px auto;
    // font-weight: 900;
    line-height: 35px;
    text-align: center;
    margin-top: 15px;
  }
  .bt-log {
    width: 200px;
    display: flex;
    justify-content: space-between;
    margin: 0px auto;
    margin-top: 30px;
    img {
      width: 35px;
      height: 35px;
    }
  }
  .xie-yi {
    font-size: 12px;
    color: #e56b5e;
    margin: 0 auto;
    text-align: center;
    margin-top: 14px;
    span {
      color: #ffd0c1;
    }
  }
  .xie-yi2 {
    font-size: 12px;
    color: #ffd0c1;
    margin: 0 auto;
    text-align: center;
  }
  .form-denglu {
    position: absolute;
    background-color: #fff;
    width: 300px;
    height: 200px;
    // top: 0px;
    // left: 50%;
  }
  .van-popup {
    width: 300px;
    border-radius: 16px;
  }
  .van-button--block {
    display: block;
    width: 50%;
  }
  .van-button {
    height: 40px;
    margin: 0 auto;
    background-color: #dc2c1f;
    border: 1px solid #dc2c1f;
  }
}
</style>
